﻿package  {
	
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	import flash.events.Event;
	import views.MenuView;

	import controllers.Controller;
	import views.RingsView;
	
	public class Main extends Sprite {
		
		public var colors:Array = [0x112489, 0xB5B3B8, 0xE9D751, 0xE7E845, 0x3171B8, 0x94C849];
		public var fade_sequence:Array = [0, 2, 4, 5, 3, 1];
		
		public var xml_path:String;
		
		private var controller:Controller;
		private var rings_view:RingsView;
		public var menu_view:MenuView;
		
		public static var instance:Main;

		public function Main() {
			stage.align = StageAlign.TOP;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			addEventListener(Event.ADDED_TO_STAGE, onAdded);
		}
		
		private function onAdded(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAdded);
			
			instance = this;
			
			xml_path = loaderInfo.parameters.hasOwnProperty("xmlpath") ? loaderInfo.parameters.xmlpath : getSWFDir() + "data.xml";
			
			controller = new Controller();
			controller.init(xml_path);
			
			menu_view = new MenuView();
			rings_view = new RingsView();

			MainMC.addChild(rings_view);
			MainMC.addChild(menu_view);
		}
		
		public function getSWFDir():String
		{
			return loaderInfo.loaderURL.substr(0 ,loaderInfo.loaderURL.lastIndexOf("/") + 1);
		}

	}
	
}
